class Solution {
public:
/*
    int findPeakElement(vector<int>& nums) {
        // 遍历查找第一个大于下一个的元素
        size_t len = nums.size();
        for(size_t i = 0; i < len-1; ++i){
            if(nums[i] > nums[i+1]) return i;
        }
        return len-1;
    }
    */

    // 二分法
    int findPeakElement(vector<int>& nums) {
        int l = 0, r = nums.size()-1;
        while(l < r){
            int mid = (l + r) >> 1;
            if(nums[mid] <= nums[mid+1])
                l = mid+1;
            else r = mid;
        }
        return l;
    }
};